'use strict';

const Controller = require('egg').Controller;
const Mock=require("mockjs")
const data=Mock.mock({
  "list|60":[{
    headline:"@ctitle",
    "status|1":["已发布","草稿"],
    "classify|1":["前端","后端"],
    "label|1":["a","b","c"],
    "reading|0-200":1,
    "likeing|0-10":1,
    "datetime":"@datetime",
    "key|+1":1,
    img:"@image(100x200,@color,zhang)",
    content:"@cword(20,30)"
  }]
})
class HomeController extends Controller {
  async index() {
    const { ctx,app } = this;
    data.list.forEach(async(item)=>{
      await app.mysql.insert("allarticles",{
        headline:item.headline,
        status:item.status,
        classify:item.classify,
        label:item.label,
        reading:item.reading,
        likeing:item.likeing,
        datetime:item.datetime,
        key:item.key,
        id:null,
        img:item.img,
        content:item.content
      })
    })
    ctx.body = {
      code:200,
      mess:"添加成功"
    }
  }
}

module.exports = HomeController;
